#include<iostream>
using namespace std;

typedef struct Node
{
	int num;
	Node *next;
}Node;

void CreateList(Node *&list, int len)
{
	list->num = 1;
	Node *q = list;
	for(int i = 2; i <= len; i++)
	{
		Node *p = new Node();
		p->num = i;
		q->next = p;
		q = p;
	}
	q->next = list;
}


int Kill(Node *&list, int val)
{
	Node *p = list;
	int cnt = 1;
	while(p->next!=p)
	{
		cnt++;
		p = p->next;
		if(cnt == val-1)
		{
			cnt = 0;
			Node *temp = p->next;
			p->next = p->next->next;
			delete(temp);
		}
	}	
	return p->num;
}

int main()
{
	int n;
	cin >>n;
	Node *list = new Node();
	CreateList(list, n);
	int val;
	cin >> val;
	int theResult = Kill(list, val);
	cout << theResult;
	
	return 0;
} 
